package com.atguigu.chaptar5

import scala.collection.mutable.ListBuffer

object $04_MutableList {
  def main(args: Array[String]): Unit = {
    //1.伴生对象创建
    val listBuffer = ListBuffer(1, 2, 3, 4, 5)
    //2.new ,可变所以不用指定长度
    val listBuffer1 = new ListBuffer[Int]()
    //3.添加元素或集合
    listBuffer.+=(6)
    println(listBuffer)
    val listBuffer2 = listBuffer.++(Array(11, 22, 33))
    //4.删除元素
    val listBuffer3 = listBuffer.-(1)
    listBuffer.-=(1)
    listBuffer.--=(List(2,3,4))
      //remove
    listBuffer.remove(0)
    //5.获取元素
    listBuffer(0)
    //6.修改元素
    listBuffer(0)=100
      //update
    listBuffer.update(0,1000)
      //updated
      val listBuffer4 = listBuffer.updated(0, 111)
    //7.可变List转不可变List
    listBuffer.toList
  }

}
